package com.zc.common.utils;

/**
 * ClassName:UserThreadLocal
 * Description:
 * DateTime: 2025/9/22 10:52
 * Author: zc
 * Version: 1.0
 */
public class UserThreadLocal {


    private static final ThreadLocal<Long> USER_HOLDER = new ThreadLocal<>();

    /**
     * 设置当前线程的用户信息
     *
     * @param userId 用户信息
     */
    public static void setUserId(Long userId) {
        USER_HOLDER.set(userId);
    }

    /**
     * 获取当前线程的用户信息
     *
     * @return 用户信息
     */
    public static Long getUserId() {
        return USER_HOLDER.get();
    }

    /**
     * 清除当前线程的用户信息
     */
    public static void clear() {
        USER_HOLDER.remove();
    }
}
